package com.zsy.controller;

import com.zsy.pojo.Dept;
import com.zsy.pojo.Result;
import com.zsy.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zhengsuyang
 * @Desc:
 * @create: 2025-09-10 15:58
 **/
@RestController
@RequestMapping("/depts")
@Slf4j
public class DeptController {
    @Autowired
    private DeptService deptService;

    /**
     * 查询部门列表
     * @return
     */
    @GetMapping
    public Result queryDeptList(){
        List<Dept> list = deptService.queryDeptList();
        return Result.success(list);
    }

    /**
     * 根据id查询部门
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result queryDeptById(@PathVariable Integer id){
       Dept dept = deptService.queryDeptById(id);
       return Result.success(dept);
    }

    /**
     * 新增部门
     * @param dept
     * @return
     */
    @PostMapping
    public Result addDept(@RequestBody Dept dept){
        deptService.addDept(dept);
        return Result.success();
    }

    /**
     * 根据id修改部门
     * @param dept
     * @return
     */
    @PutMapping
    public Result updateDept(@RequestBody Dept dept){
        deptService.updateDept(dept);
        return Result.success();
    }

    /**
     * 根据id删除部门
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteDeptById(@RequestParam Integer id){
        deptService.deleteDeptById(id);
        return Result.success();
    }

}
